% The main use of this function is to Compute Matrix R by wwb June 1st

function R = findR(rimS, p, Nmax, Q)
p1 = p(1); p2 = p(2); p3 = p(3);
R = zeros(8,Nmax+1);     % Should I add 1 here?

for i = 1:8
    Pre_i = sum(rimS(i,:));
    for m = 1 : Pre_i
        for tt = 1 : (Nmax+1)    % True number comes is (tt-1)
            R(i,m) = R(i,m)+Q(i,tt) * poisscdf(tt-1,3);  % I assume the parameter of poisson is 3.
        end
    end
end
end